<?php
namespace Admin\Controller;

use Utuo\BackgroundController;

class ActivityClassController extends BackgroundController {
	
	private $status = array(
		'0' => '关闭',
		'1' => '开启'
	);
	
	public function _initialize() {
		$this->setControllerTitle("活动类型管理");
		$this->setActionTitle(array(
			'index' => '活动类型列表',
			'add' => '活动类型添加',
			'modify' => '活动类型修改',
		));
		$this->setActionNav("index,add");
	}
	
	// 活动类型列表
	public function indexAction() {
		$this->getActivityClassList();
	}
	
	// 活动添加
	public function addAction() {
		$activityClass = array();
		$activityClass['statusRadio'] = $this->getRadio("status", $this->status);
		$this->assign("activityClass", $activityClass);
		$this->display("save");
	}
	
	// 活动修改
	public function modifyAction() {
		$activityClass = $this->getOneById("ActivityClass");
		$activityClass['statusRadio'] = $this->getRadio("status", $this->status, $activityClass['status']);
		$this->assign("activityClass", $activityClass);
		$this->display("save");
	}
	
	// 活动保存
	public function savePostAction() {
		$id = I("id", 0, "intval");
		$d = D("ActivityClass");
		if($d->create()) {
			$result = !empty($d->id) ? $d->save() : $d->add();
		}
		$result !== false and $this->ajaxSuccess("保存成功");
		$this->ajaxError("保存失败");
	}
	
	// 设置活动状态
	public function setStatusPostAction() {
		$this->ajaxSetStatus("ActivityClass");
	}
	
	// 删除数据
	public function removePostAction() {
		$this->ajaxRemove("ActivityClass");
	}
	
	// 彻底删除
	public function deletePostAction() {
		$this->ajaxDelete('ActivityClass');
	}
	
	// 恢复用户
	public function restorePostAction() {
		$this->ajaxRestore('ActivityClass');
	}
	
	// 获取列表
	private function getActivityClassList() {
		$page = $this->getPage();
		$pagesize = $this->getPageSize();
		$pid = I('pid', 0, 'intval');
		$activityClassLists = M('ActivityClass')->where('status=1 and is_deleted=0')->limit($pagesize)->page($page)->select();
		$activityClassCount = M('ActivityClass')->where('status=1 and is_deleted=0')->count();
		$this->assign('activityClassLists', $activityClassLists);
		$this->showPage($activityClassCount, $pagesize);
		$this->display();
	}
	
}